import math
import re
from urllib import parse

import requests
from lxml import etree


def proxy():
    # 获取代理的代码
    proxies = {'http': 'http://220.164.227.40:23564'}  # 代理ip
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36',
        }
    return proxies, headers

# 获取cookies
proxies, headers = proxy()  # 返回的是 代理  和 headers {'http': 'http://27.205.120.46:894'} {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36', 'Proxy-Authorization': 'Basic ZGV2ZWxvcGVyQHRvbW1tdC5jb206VG9tbW10NjY2'}
url = 'https://weixin.sogou.com/'
session = requests.session()
response = session.get(url, proxies=proxies, headers=headers)
str1 = parse.quote('一')  # 对参数进行加密
url = 'https://weixin.sogou.com/weixin?type=2&ie=utf8&query={}&tsn=1&ft=&et=&interation=&wxid=&usip='.format(str1)



proxies, headers = proxy()
headers['Referer'] = url
print(proxies)
response1 = session.get(url, proxies=proxies, headers=headers, timeout=5, verify=False)
print(11, response1.url)
# 转化为可使用xpath的对象
html1 = etree.HTML(response1.content)
print(response1.status_code)
new_count = html1.xpath('//div[@class="mun"]/text()')[0]

new_count = re.findall(r'\d+', new_count)[0]
page_num = math.ceil(int(new_count) / 10)

print(new_count, page_num)